package com.gxa.controller;

import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.CarInsuranceDTO;
import com.gxa.domain.entity.CarInsurance;
import com.gxa.domain.vo.CarInsuranceVO;
import com.gxa.service.CarInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * User: gxb
 * Date: 2024/07/17  10:10
 * Description:
 * Version: V1.0
 */
@Api(tags = "车辆管理-车辆保险")
@RestController
@RequestMapping("/logistics/carinsurance")
@Slf4j
public class CarInsuranceController {
    @Autowired
    private CarInsuranceService carInsuranceService;


    //定义请求路径 并且请求方式限制为get
    @ApiOperation("查询车辆保险")
    @GetMapping("/list")
    public RespResult list() {
        //1.查询所有的车辆保险
        List<CarInsurance> carInsuranceList = carInsuranceService.findCarInsuranceAll();
        //2.返回给前端
        return RespResult.success(carInsuranceList);
    }

    @ApiOperation("根据id查找车辆保险")
    @GetMapping("/find")
    public RespResult find(Long id) {//springmvc会自动进行参数绑定
        //调用service进行业务处理
        CarInsuranceVO carInsuranceVO = carInsuranceService.findCarInsuranceById(id);
        //返回结果给前端
        return RespResult.success(carInsuranceVO);
    }

    @ApiOperation("添加车辆保险")
    @PostMapping("/add")
    public RespResult add(@RequestBody CarInsurance carInsurance) {//@RequestBody 前端给后端发送json数据
        carInsuranceService.insertCarInsurance(carInsurance);
        return RespResult.success();
    }

    @ApiOperation("修改车辆保险信息")
    @PostMapping("/update")
    public RespResult update(@RequestBody CarInsurance carInsurance) {//@RequestBody 前端给后端发送json数据
        carInsuranceService.updateCarInsurance(carInsurance);
        return RespResult.success();
    }


    @ApiOperation("删除车辆保险")
    @PostMapping("/delete")
    public RespResult delete(Long id) {//springmvc会自动进行参数绑定
        //调用service进行业务处理
        carInsuranceService.deleteCarInsuranceById(id);
        //返回结果给前端
        return RespResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("/findCarInsuranceByWhere")
    public RespResult list(CarInsuranceDTO carInsuranceDTO) {
        //1.查询页面数据
        List<CarInsurance> carManageList = carInsuranceService.findCarInsuranceByWhere(carInsuranceDTO);

        //2.返回给前端
        return RespResult.success(carManageList);
    }
}
